| Contents > Library Reference > Data structures |
Data structures
General purpose objects such as a dictionary and a string list.
Objects and Structures
| Dict | A dictionary, mapping a key string to a value string. | |
| StringList | Manages a list of strings. |
Functions
| void sort(void* data, int count, int size, string order) | Sorts an array of objects (or structures). data is a pointer to the first element in the array. The order specifier is a string which first states the direction to sort, followed by the offset into the object of the field to sort. The direction is specified as a '>' for ascending or a '<' for descending. Either one or two fields may be sorted on. |
| Contents > Library Reference > Data structures > Dict object |
Dict
A Dict object implements a dictionary, which is a mapping from a string key to a string value. All keys in the dictionary must be unique.
Object Properties
| int count | Gets the number of items in the dictionary. |
Object Methods
| void clear() | Removes all the items from the dictionary. | |
| int add(string key, string value) | Adds value to the dictionary and associate it with key. Returns the new number of items. | |
| int del(string key) | Deletes the specified key and its associated value from the dictionary. Returns the number of remaining items. | |
| string find(string key) | Returns the value associated with key, or the empty string if the key is not found. | |
| bool has(string key) | Returns true if key is in the dictionary. | |
| string key(int index) | Returns the key for the given index in the dictionary. | |
| string value(int index) | Returns the value for the given index in the dictionary. |
| Contents > Library Reference > Data structures > StringList object |
StringList
A StringList is an ordered list of strings.
Object Properties
| int count | Gets the number of strings in the list |
Object Methods
| void clear() | Removes all the strings from the list. | |
| int add(string str) | Adds the string str to the end of the list and returns the new number of strings in the list. | |
| int insert(int index, string str) | Inserts the string str into the list at position index and returns the new number of strings in the list. | |
| int del(int index) | Removes the string at position index and returns the number of strings remaining in the list. | |
| int find(string str) | Finds the string str in the string list and returns the string's index in the list or -1 if the string is not found. | |
| void sort(bool caseSensitive) | Sorts the strings in the list, using the specified case sensitivity. | |
| int tokens(string str, string toks) | Splits the string str into multiple tokens, and adds each token to the list. Tokens are specified as characters in toks. The number of tokens found is returned. | |
| string item(int index) | Retrieves the string at location index. Returns the empty string if the index is invalid. |
| Contents > Library Reference > Data structures > Dict object > clear |
Dict.clear
void clear() |
Removes all the items from the dictionary.
| Contents > Library Reference > Data structures > Dict object > add |
Dict.add
int add(string key, string value) |
Parameters:
| key | key | |
| value | value |
Return value: number of items
Adds value to the dictionary and associate it with key. Returns the new number of items.
| Contents > Library Reference > Data structures > Dict object > del |
Dict.del
int del(string key) |
Parameters:
| key | key |
Return value: number of items
Deletes the specified key and its associated value from the dictionary. Returns the number of remaining items.
| Contents > Library Reference > Data structures > Dict object > find |
Dict.find
string find(string key) |
Parameters:
| key | key |
Return value: value
Returns the value associated with key, or the empty string if the key is not found.
| Contents > Library Reference > Data structures > Dict object > has |
Dict.has
bool has(string key) |
Parameters:
| key | key |
Return value: true if value is found
Returns true if key is in the dictionary.
| Contents > Library Reference > Data structures > Dict object > key |
Dict.key
string key(int index) |
Parameters:
| index | index |
Return value: key at index
Returns the key for the given index in the dictionary.
| Contents > Library Reference > Data structures > Dict object > value |
Dict.value
string value(int index) |
Parameters:
| index | index |
Return value: value at index
Returns the value for the given index in the dictionary.
| Contents > Library Reference > Data structures > StringList object > clear |
StringList.clear
void clear() |
Removes all the strings from the list.
| Contents > Library Reference > Data structures > StringList object > add |
StringList.add
int add(string str) |
Parameters:
| str | string to add |
Return value: new number of strings in the list
Adds the string str to the end of the list and returns the new number of strings in the list.
| Contents > Library Reference > Data structures > StringList object > insert |
StringList.insert
int insert(int index, string str) |
Parameters:
| index | insertion location | |
| str | string to insert |
Return value: new number of strings in the list
Inserts the string str into the list at position index and returns the new number of strings in the list.
| Contents > Library Reference > Data structures > StringList object > del |
StringList.del
int del(int index) |
Parameters:
| index | index of string to delete |
Return value: the remaining number of strings in the list
Removes the string at position index and returns the number of strings remaining in the list.
| Contents > Library Reference > Data structures > StringList object > find |
StringList.find
int find(string str) |
Parameters:
| str | string to find |
Return value: index of string
Finds the string str in the string list and returns the string's index in the list or -1 if the string is not found.
| Contents > Library Reference > Data structures > StringList object > sort |
StringList.sort
void sort(bool caseSensitive) |
Parameters:
| caseSensitive | true for case sensitive sort |
Sorts the strings in the list, using the specified case sensitivity.
| Contents > Library Reference > Data structures > StringList object > tokens |
StringList.tokens
int tokens(string str, string toks) |
Parameters:
| str | string to tokenize | |
| toks | separators |
Return value: token count
Splits the string str into multiple tokens, and adds each token to the list. Tokens are specified as characters in toks. The number of tokens found is returned.
| Contents > Library Reference > Data structures > StringList object > item |
StringList.item
string item(int index) |
Parameters:
| index | index of string to retrieve |
Return value: string at the specified location
Retrieves the string at location index. Returns the empty string if the index is invalid.
| Contents > Library Reference > Data structures > sort |
sort
void sort(void* data, int count, int size, string order) |
Parameters:
| data | data to be sorted | |
| count | count of objects to be sorted | |
| size | size of each object | |
| order | order specifier |
Sorts an array of objects (or structures). data is a pointer to the first element in the array. The order specifier is a string which first states the direction to sort, followed by the offset into the object of the field to sort. The direction is specified as a '>' for ascending or a '<' for descending. Either one or two fields may be sorted on.
Note: This function is implemented by the OrbSort native add-in. To use it you must #include "OrbSort.oc".Example:
Sort an array of Persons in a variety of ways.
struct Person {
string name; // offset 0
int age; // offset 1
};
Person people[2];
void SortPeople() {
// sort by name, ascending
sort(people, 2, sizeof(Person), ">0");
// sort by age, descending
sort(people, 2, sizeof(Person), "<1");
// sort by age first, followed by name
sort(people, 2, sizeof(Person), "<1<0");
} |